FROM mcr.microsoft.com/dotnet/aspnet:8.0 AS base
WORKDIR /app
EXPOSE 80
EXPOSE 443

# 设置环境变量
ENV ASPNETCORE_ENVIRONMENT=Production
ENV ASPNETCORE_URLS=http://+:80

FROM mcr.microsoft.com/dotnet/sdk:8.0 AS build
WORKDIR /src

# 复制项目文件
COPY ["BXS.API.csproj", "BXS.API/"]
RUN dotnet restore "BXS.API/BXS.API.csproj"

# 复制源代码
COPY . .
WORKDIR "/src/BXS.API"

# 构建项目
RUN dotnet build "BXS.API.csproj" -c Release -o /app/build

# 发布
FROM build AS publish
RUN dotnet publish "BXS.API.csproj" -c Release -o /app/publish /p:UseAppHost=false

# 最终镜像
FROM base AS final
WORKDIR /app

# 创建日志目录
RUN mkdir -p /var/log/bxs-api

# 复制发布文件
COPY --from=publish /app/publish .

# 设置用户权限
RUN chown -R 1001:1001 /app /var/log/bxs-api
USER 1001

ENTRYPOINT ["dotnet", "BXS.API.dll"] 